package com.example.mobile2021606163crw0330;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView TV;
    private EditText ed1;
    private EditText ed2;
    private Button btn1;
    private Button btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        TV = (TextView) findViewById(R.id.TV);
        ed1 = (EditText) findViewById(R.id.ed1);
        ed2 = (EditText) findViewById(R.id.ed2);
        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);

    }

    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn1:
                if (ed1.length() == 0){
                    Toast.makeText(MainActivity.this,"用户名为空",Toast.LENGTH_SHORT).show();
                }
                else if (ed2.length() == 0){
                    Toast.makeText(MainActivity.this,"密码为空",Toast.LENGTH_SHORT).show();
                }else {
                    if (ed1.getText().toString().equals("leo")&
                            ed2.getText().toString().equals("123456")){
                        Log.i("登录", "onClick:登录成功 ");
                        Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
                    }else {
                        Log.i("登录", "onClick:登录失败");
                        Toast.makeText(MainActivity.this,"登录失败",Toast.LENGTH_SHORT).show();
                    }

                }
            case R.id.btn2:
                ed1.setText(null);
                ed2.setText(null);

        }
    }
}